package com.example.campus.mapper;

import com.example.campus.pojo.entity.Category;
import com.example.campus.pojo.entity.LostAndFoundInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface InfoCateLinkMapper {

    void insertBatch(Long infoId, List<Long> categoryIds);

    @Delete("delete from info_category_relation where info_id = #{infoId}")
    void deleteByInfoId(Long infoId);

    @Delete("delete from info_category_relation where category_id = #{categoryId}")
    void deleteByCategoryId(Long categoryId);

    @Select("select c.* from category c left join info_category_relation r on c.id = r.category_id where r.info_id = #{infoId}")
    List<Category> getByInfoId(Long infoId);

    @Select("select r.info_id from info_category_relation r where r.category_id = #{categoryId}")
    List<Long> getByCategoryId(Long id);
}
